<?php

/* 热门关注 */
class HotkeywordModel extends BaseModel
{
    var $table  = 'hot_keyword';
    var $prikey = 'keyword_id';
    var $_name  = 'hotkeyword';
    var $_autov = array(
        'keyword_name' => array(
            'required'  => true,
            'filter'    => 'trim',
        ),
        'link' => array(
            'required'  => true,
            'filter'    => 'trim',
        ),
        'recom_id' => array(
            'required'  => true,
            'filter'    => 'intval',
        ),
    );
    
    function get_recommended_keyword($recom_ids, $cache = false)
    {
        
        if(!is_array($recom_ids)){
            $recom_ids = array($recom_ids);
        }
        
        $cacheServer = cache_server();
        $cacheKey = "get_recommended_keyword_" . implode("_", $recom_ids);
        $arr = $cacheServer->hGet($this->_name, $cacheKey);
        
        if($arr === false || $cache === false){
            $keyword_mod =& m('hotkeyword');
            $keyword_list = $keyword_mod->find(array(
                    'conditions' => 'recom_id ' . db_create_in($recom_ids),
                    'order'     => 'sort_order,keyword_id DESC',
                ));

            foreach($keyword_list as $row)
            {
                $arr[$row['recom_id']][$row['keyword_id']]['keyword_id']   = $row['keyword_id'];
                $arr[$row['recom_id']][$row['keyword_id']]['keyword_name'] = $row['keyword_name'];
                $arr[$row['recom_id']][$row['keyword_id']]['link']         =  $row['link'];
            }    
            
            $cacheServer->hSet($this->_name, $cacheKey, $arr, $this->expire);
        }
        
        return $arr;
        
    }

}

?>